﻿@{
    ViewBag.Title = "DQIndex";
    Layout = "~/Views/Shared/_Main.cshtml";
}
<script src="../../Scripts/jquery.autocomplete.js" type="text/javascript"></script>
<link href="../../CSS/jquery.autocomplete.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
    $(function () {
        $.post("/GenericSearch/GetDQTables?dbName=" + encodeURI($.getUrlParam("dbName")), { tableName: $("#txtTableName").val(), t: Date() }, function (result) {
            if (result.length > 0) {
                //                $("#hddTabsCount").val(result.length);
                //                for (var i = 0; i < result.length; i++) {
                //                    var contentValue = "<iframe scrolling='no' frameborder='0'  src='/GenericSearch/DQItem?schemaName=" + encodeURI(result[i].SchemaName) + "&tableName=" + encodeURI(result[i].TableName) + "' style='width:99%;height:98%;padding-top:5px;padding-left:5px;overflow-y:'></iframe>";
                //                    $('#divTabs').tabs('add', {
                //                        title: result[i].TableName,
                //                        content: contentValue,
                //                        iconCls: 'icon-save',
                //                        cache: false,
                //                        selected: (i == 0 ? true : false)
                //                    });
                //                }

                $('#txtTableName').autocomplete(result, {
                    max: result.length,    //列表里的条目数
                    minChars: 0,    //自动完成激活之前填入的最小字符
                    width: 495,     //提示的宽度，溢出隐藏
                    scrollHeight: 300,   //提示的高度，溢出显示滚动条
                    matchContains: true,    //包含匹配，就是data参数里的数据，是否只要包含文本框里的数据就显示
                    autoFill: false,    //自动填充
                    formatItem: function (row, i, max) {
                        return row.TableName;
                    },
                    formatMatch: function (row, i, max) {
                        return row.TableName;
                    },
                    formatResult: function (row) {
                        return row.TableName;
                    }
                }).result(function (event, row, formatted) {

                });
            }
        });

        $('#divTabs').tabs({
            onSelect: function () {
                var tab = $('#divTabs').tabs('getSelected');
                $('#divTabs').tabs('update', {
                    tab: tab,
                    options: {
                        content: tab[0].innerHTML
                    }
                });
            }
        });
    });

    function btnSearchClick() {
        var tabsCount = $("#hddTabsCount").val();
        for (var i = 0; i < tabsCount; i++) {
            $('#divTabs').tabs('close', 0);
        }
        $.post("/GenericSearch/GetDQTables?dbName=" + encodeURI($.getUrlParam("dbName")), { tableName: $("#txtTableName").val(), t: Date() }, function (result) {
            $("#hddTabsCount").val("0");
            if (result && result.length > 0) {
                $("#hddTabsCount").val(result.length);
                for (var i = 0; i < result.length; i++) {
                    var contentValue = "<iframe scrolling='no' frameborder='0'  src='/GenericSearch/DQItem?dbName=" + encodeURI($.getUrlParam("dbName"))+"&schemaName=" + encodeURI(result[i].SchemaName) + "&tableName=" + encodeURI(result[i].TableName) + "' style='width:99%;height:98%;padding-top:5px;padding-left:5px;'></iframe>"
                    $('#divTabs').tabs('add', {
                        title: result[i].TableName,
                        content: contentValue,
                        iconCls: 'icon-save',
                        cache: false,
                        selected: (i == 0 ? true : false)
                    });
                }
            }
        });
    }
</script>
<input type="hidden" id="hddTabsCount" value="0" />
<div style="margin: 5px;">
    <div id="p" class="easyui-panel" style="width: 1013px;" data-options="title:'DQ搜索',iconCls:'icon-search'">
        <table>
            <tr>
                <td style="text-align: right; width: 60px;">
                    DQ表名：
                </td>
                <td style="width: 500px;">
                    <input type="text" id="txtTableName" style="width: 98%;" />
                </td>
                <td>
                    &nbsp;&nbsp; <a href="javascript:void(0)" onclick="btnSearchClick()" class="easyui-linkbutton"
                        data-options="iconCls:'icon-search'">查询</a>
                </td>
            </tr>
        </table>
    </div>
</div>
<div id="divTabs" class="easyui-tabs" style="width: 1013px; height: 450px; margin-left: 5px;">
</div>
